﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Painter3D.RenderSys
{
    /// <summary>
    /// 创建的各种着色器被该类管理，提供查找功能
    /// </summary>
    class ShaderManager
    {
        static private List<Shader> shaders = new List<Shader>();

        static public void LoadDefaultShader()
        {
            Shader.Load(@"F:\Painter3D\Resource\Shader\Pink.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\SolidColor.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\VertexColor.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\Texture.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\Font.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\PhongLight.glsl");
            Shader.Load(@"F:\Painter3D\Resource\Shader\SkyBox.glsl");
        }

        static public Shader Find(string name)
        {
            return shaders.Find((s) => { return s.shaderName == name; });
        }

        static public bool Add(Shader shader)
        {
            if (shaders.Find((s) => { return s.shaderName == shader.shaderName; }) == null)
            {
                shaders.Add(shader);
                return true;
            }
            else
            {
                return false;
            }
        }

        static public bool Delete(Shader shader)
        {
            return shaders.Remove(shader);
        }

        static public void Clear()
        {
            while (shaders.Count != 0)
            {
                shaders[0].Dispose();
            }
        }
    }
}
